#include <vector>
#include <string>

#include "echiquier.h"
#include "piece.h"
#include "jeu.h"

using namespace std;

//utilitaires

void zones_couvertes(vector<int> *tab1, vector<int> *tab2, Echiquier *echi)
{
	int i,j,k;
	for (i =0; i<6; i++)
	{
		for (j = 0; j<8; j++)
		{
			for (k = 0; k<6; k++)
			{				
				if (echi->get_couleur(i,j,k) == 0)
				{
					echi->get_piece(i,j,k)->deplacement(echi, tab1);
				}
				else if (echi->get_couleur(i,j,k) == 1)
				{
					echi->get_piece(i,j,k)->deplacement(echi, tab2);
				}
			}
		}
	}
	supprime_doublons(tab1);
	supprime_doublons(tab2);
} 

void supprime_doublons(vector<int> *tab)
{
	int test[6][8][6] = {{{0}}};
	
	unsigned int i = 0;
	
	while(i<tab->size())
	{
		if (test[(*tab)[i]][(*tab)[i+1]][(*tab)[i+2]] == 0)
		{
			test[(*tab)[i]][(*tab)[i+1]][(*tab)[i+2]] = 1 ;
			i += 3;
		}
		else
		{
			tab->erase(tab->begin()+i,tab->begin()+i+3);
		}
	}
}

bool appartient(int x, int y, int z, vector<int> *tab)
{
	int i;
	for(i =0; i<(tab->size()); i+=3)
	{
		if ( (x == (*tab)[i]) && (y == (*tab)[i+1]) && (z == (*tab)[i+2]))
		{
			return true;
		}
	}
	return false;
}
